<template>
	<el-dialog title="环境维护配置" :visible.sync="dialogVisible" width="1000px" @close="handleClose"
		:close-on-click-modal="false">
		<div slot="title" class="dialog-header-title">
			<i class="el-icon-edit-outline"></i>
			<span>环境维护配置</span>
		</div>

		<div class="smp-search" v-if="dialogVisible">
			<el-form :inline="false" label-width="110px" size="mini"  ref="form" :model="form" :rules="rules">

				<el-row>
						<el-col :span="12" prop="requireType">
							<el-form-item label="操作类型:" >
								<el-select v-model="form.requireType" style="width: 100%"   
								placeholder="申请类型" 
								disabled>
									<el-option v-for="item in dict('SMP0025')" :key="item.itemCode" :label="item.itemName" :value="item.itemCode"></el-option>
								</el-select>
							</el-form-item>
						</el-col> 
						
						<el-col :span="12">
							<el-form-item label="所属系统:" prop="systemNo">
								<el-select v-model="form.systemNo" disabled style="width: 100%" filterable remote reserve-keyword
									placeholder="请输入系统编号或名称" :remote-method="getsystems">
									<el-option v-for="item in systemListAll" :key="item.systemNo" :label="item.systemName"
										:value="item.systemNo">
										<span style="float: left;margin-left: 3px;">{{ item.systemNo }}</span>
										<span style="float: right;margin-right: 3px;">{{ item.systemName }}</span>
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>
						
						<el-col :span="12">
							<el-form-item label="主机名称:" prop="hostName">
								<el-input v-model="form.hostName" placeholder="请输入主机名称" disabled></el-input>
							</el-form-item>
						</el-col>
						
				
						<el-col :span="12">
							<el-form-item label="环境类型:" prop="envirType">
								<el-select v-model="form.envirType" disabled style="width: 100%" placeholder="环境类型" >
									<el-option v-for="item in dict('SMP0026')" :key="item.itemCode" :label="item.itemName" :value="item.itemCode"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
				
						<el-col :span="12">
							<el-form-item label="ESB环境IP:" prop="esbAddr">	
								<el-select v-model="form.esbAddr" disabled style="width: 100%" placeholder="请选择ESB环境IP" >
									<!-- <el-option v-for="item in dict('SMP0016')" :key="item.itemCode" :label="item.itemName" :value="item.itemCode"></el-option> -->
									<el-option v-for="item in esbEnvironmentList" :key="item.ip" :label="item.ip+'('+dictName(item.esbFlg,'SMP0031')+')'" :value="item.ip"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						
						<el-col :span="12">
							<el-form-item label="系统IP:" prop="systemCurrentAddr">
								<el-input v-model="form.systemCurrentAddr" disabled placeholder="eg:tcp://127.0.0.1"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="12">
							<el-form-item label="HOSTS" prop="hosts">
								<el-input v-model="form.hosts"></el-input>
							</el-form-item>
						</el-col>
						
				</el-row>

			</el-form>
		</div>
		
		<span slot="footer" class="dialog-footer">
			<el-button size="mini"  type="primary" @click="onSubmit">确定</el-button>
			<el-button size="mini"  @click="closeDialog">取消</el-button>
		</span>
	</el-dialog>
</template>

<script>
	"use strict";
	import {updateApplyEnvironmentInfo} from '@/api/demand.js';
	import {getEsbEnvironmentByEsbFlg} from '@/api/environment.js';
	export default {
		
		data() {
			return {
				dialogVisible: false,
				esbEnvironmentList: [],
				rules: {
					hosts: [{
						required: true,
						message: "域名(hosts)不能为空",
						trigger: ['blur', 'change']
					}]
				},
				form: {
					requireType: '',
					systemNo: '',
					hostName: '',
					envirType: '',
					esbAddr: '',
					systemCurrentAddr: '',
					hosts: ''
				},
				
			};
		},

		created() {
			this.getEsbEnvironmentList();
		},
			
		methods: {
			
			getEsbEnvironmentList() {
				getEsbEnvironmentByEsbFlg({}).then(response => {
					this.esbEnvironmentList = response.data.extend;
				})
			},
						
			onSubmit() {
				this.updateApplyEnvironmentInfo();
			},

			
			updateApplyEnvironmentInfo() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						updateApplyEnvironmentInfo(this.form).then(response => {
							
							this.dialogVisible = false;
							this.reset();
							this.$emit("getList");

						}).catch(error => {
							this.$message({
						duration:5000,
								type: 'error',
								message: '环境维护配置失败！'
							});
							this.reset();
							this.dialogVisible = false;
						});
					}
				})

			},

			showDialog(row) {
				this.form = row;
				this.dialogVisible = true;

			},

			closeDialog() {
				this.dialogVisible = false;
				this.reset();
			},

			handleClose() {
				this.dialogVisible = false;
				this.reset();
			},
		},

	}
</script>

<style>
</style>
